﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Shove.Web.UI;

public partial class UserControls_Register : UCBase
{
    public UserControls_Register()
    {
        Name = "用户注册";

        swpas = new ShoveWebPartAttribute[11];

        swpas[0] = new ShoveWebPartAttribute_Int("控件宽度", "1,1004", 700, "控件宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("导航行高", "1,400", 28, "导航行高");
        swpas[2] = new ShoveWebPartAttribute_Int("导航图片1单元格宽度", "1,1000", 106, "导航图片1单元格宽度");

        swpas[3] = new ShoveWebPartAttribute_Color("控件边框颜色", "#cccccc", "控件边框颜色");

        swpas[4] = new ShoveWebPartAttribute_Text("导航字体颜色", "", "title14_bai", "导航字体颜色");
        swpas[5] = new ShoveWebPartAttribute_Text("注册协议标题样式","","td14","注册协议标题样式");

        swpas[6] = new ShoveWebPartAttribute_Image("导航背景图片1", "", "images/UserControls/title_bg_1.jpg", "导航背景图片1");
        swpas[7] = new ShoveWebPartAttribute_Image("导航背景图片2", "", "images/UserControls/title_bg_hui.jpg", "导航背景图片2");
        swpas[8] = new ShoveWebPartAttribute_Image("注册协议背景图片", "", "images/UserControls/category_bg_1.jpg", "注册协议背景图片");
        swpas[9] = new ShoveWebPartAttribute_Image("确定按钮图片", "", "images/UserControls/button_ok.jpg", "确定按钮图片");
        swpas[10] = new ShoveWebPartAttribute_Image("取消按钮图片", "", "images/UserControls/button_qx.jpg", "取消按钮图片");
    }

    private void InitlayOut()
    {
        tabctr.Width = swpAttributes[0];
        tabctr.BgColor = swpAttributes[3];

        tdNum.Height = swpAttributes[1];
        tdNum.Width = swpAttributes[2];
        tdNum.Attributes.Add("class", swpAttributes[4]);
        tdNum.Style.Add("background-image", "url('" + swpAttributes[6] + "')");
        tdsign.Style.Add("background-image", "url('" + swpAttributes[7] + "')");
        tdsign.Width = (Shove._Convert.StrToInt(swpAttributes[0], 700) - Shove._Convert.StrToInt(swpAttributes[2], 106)).ToString();

        tdtishi.Attributes.Add("class", swpAttributes[5]);
        tdtishi.Style.Add("background-image", "url('" + swpAttributes[8] + "')");

        ibOK.ImageUrl = "~/" + swpAttributes[9];
        ibCancel.ImageUrl = "~/" + swpAttributes[10];
    }

    protected void Page_Load(object sender, EventArgs e)
    {        
        AjaxPro.Utility.RegisterTypeForAjax(typeof(Ajax.ShopCustomer));

        InitlayOut();
        LoadDate();
        LoadProvince();
        LoadCity();
        ddlProvince.Attributes.Add("onchange", "ddlProvinceChange(this)");
        ddlCity.Attributes.Add("onchange", "ddlCityChange(this)");
    }

    /// <summary>
    /// 绑定省份
    /// </summary>
    private void LoadProvince()
    {
        ddlProvince.DataSource = BLL.CommBLL.GetProvince();
        ddlProvince.DataTextField = "Name";
        ddlProvince.DataValueField = "ID";
        ddlProvince.DataBind();
    }

    private void LoadCity()
    {
        ddlCity.DataSource = Ajax.ShopCustomer.GetCity(1);
        ddlCity.DataTextField = "Name";
        ddlCity.DataValueField = "ID";
        ddlCity.DataBind();
    }

    private void LoadDate()
    {
        for (int i = 1960; i < 2100; i++)
        {
            ddlYear.Items.Add(i.ToString());
        }
        for (int i = 1; i <= 12; i++)
        {
            ddlMonth.Items.Add(i.ToString());
        }
        for (int i = 1; i <= 31; i++)
        {
            ddlDay.Items.Add(i.ToString());
        }
    }

    protected void ibOK_Click(object sender, ImageClickEventArgs e)
    {
        if (Page.IsValid)
        {
            //DataTable dt = new DAL.Tables.tbl_Customer().Open("", "CustomerNo = '" + txtUserName.Text.Trim() + "'", "");
            //if (dt != null && dt.Rows.Count > 0)
            //{
            //    Shove._Web.JavaScript.Alert(this.Page, "此用户名已经被注册！");

            //    return;
            //}

            string CustomerNo = txtUserName.Text.Trim();
            string CustomerName =  txtName.Text.Trim();
            Int16 CustomerTypeID = 11;                     //网店注册会员类型
            string Password1 = PublicFunction.EncryptPassword(txtPassword.Text.Trim());
            string Password2 = PublicFunction.EncryptPassword(txtPassword.Text.Trim());  
            string Tel = txtTel1.Text.Trim();
            string Mobile = txtTel2.Text.Trim();
            string QQ = "";
            string Email = txtEmail.Text.Trim();
            string PostCode = txtZip.Text.Trim();
            int CityID = Shove._Convert.StrToInt(hCity.Value, 0); //Shove._Convert.StrToInt(ddlCity.SelectedValue, 0);
            string Address =  txtAddress.Text.Trim();
            string Fax = "";                    //传真
            string Other = "";                  //其它联系方式
            string Sex = rblSex.SelectedValue;
            DateTime Birthday = Shove._Convert.StrToDateTime(ddlYear.SelectedValue + "-" + ddlMonth.SelectedValue + "-" + ddlDay.SelectedValue, DateTime.Now.ToString("yyyy-MM-dd"));
            Int16 CertTypeID = 1;               //证书类型ID
            string CertNo = "";                 //证书编号
            int BankTypeID = 1;                 //银行名
            string BankNameDetail = "";         //开户行名
            string BankCardNo = "";             //帐号
            string BankCustName = "";           //帐户名
            int DeptID = 1;                     //部门ID
            long RegisterOperID = -1;           //注册操作员
            string Remark = "商城注册会员";  
            long RegisterShopID = _Site.ID;     //站点ID
            long SurrogateID = -1;              //代理商ID (网店前台会员，一般不享受结算奖金)
            long CommendID = -1;
            long ParentID = -1;
            Int16 LR = 0;
            bool IsLock = false;                //是否允许登录后台
            bool IsActivation = true;           //是否激活
            bool IsSurrogate = false;           //是否为代理商            

            long NewID = 0;                     //新注册会员ID
            string ReturnDescription = "";

            int i = DAL.Procedures.P_CustomerAdd(CustomerNo, CustomerName, CustomerTypeID, Password1, Password2, Tel, Mobile, QQ, Email, PostCode, CityID, Address, Fax, Other, Sex, Birthday, CertTypeID, CertNo, BankTypeID, BankNameDetail, BankCardNo, BankCustName, DeptID,
                RegisterOperID, Remark, RegisterShopID, SurrogateID, CommendID, ParentID, LR, false, IsLock, IsActivation, IsSurrogate, ref NewID, ref ReturnDescription);
            if (i >= 0)
            {
                //立即登录
                int Result = new Login().LoginSubmit(this.Page, _Site, txtUserName.Text, txtPwd.Text, ref ReturnDescription);

                if (Result < 0)
                {
                    Shove._Web.JavaScript.Alert(this.Page, ReturnDescription);

                    return;
                }

                Response.Write("<script>alert('注册成功！');window.location='Default.aspx?PN=member_home'</script>");
            }
            else
            {
                Shove._Web.JavaScript.Alert(this.Page, ReturnDescription);

                return;
            }
        }
     }

    protected void ibCancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
   
    protected void ckOK_CheckedChanged(object sender, EventArgs e)
    {
        if (ckOK.Checked == true)
        {
            Register.ActiveViewIndex = 1;
        }
    }
}
